# -*- coding: utf-8 -*-

"""
Module implementing HelpDialog.
"""

from PyQt4.QtGui import QDialog
from PyQt4.QtCore import pyqtSignature

from Ui_HelpDlg import Ui_HelpDialog

import general

class HelpDialog(QDialog, Ui_HelpDialog):
    """
    游戏规则帮助对话框
    """
    def __init__(self, parent = None):
        """
        Constructor
        """
        QDialog.__init__(self, parent)
        self.setupUi(self)
        
        self.splitter.setSizes([100, 300])
        self.showGames()
    
    def showGames(self):
        '''获取可用的游戏模块并显示到游戏列表'''
        gameNames=[m.NAME for m in general.gameModules]
        
        self.listGame.clear()
        self.listGame.addItems(gameNames)
        self.listGame.setCurrentRow(0)
    
    @pyqtSignature("int")
    def on_listGame_currentRowChanged(self, currentRow):
        """
        槽，游戏列表所选改变
        """
        mGame=general.gameModules[currentRow]
        self.textRule.setText(mGame.HELP)

if __name__ == '__main__':
    import sys
    from PyQt4 import QtGui
    app = QtGui.QApplication(sys.argv)
    general.updateGameModules()
    ui = HelpDialog()
    ui.show()
    print ui.listGame.size()
    sys.exit(app.exec_())
